package com.woniuxy.oldmanapi.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.oldmanapi.entity.Electricity;
import com.woniuxy.oldmanapi.mapper.ElectricityMapper;
import com.woniuxy.oldmanapi.yvo.ElectricityVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ElectricityService {
    @Autowired
    ElectricityMapper electricityMapper;
    public PageInfo<ElectricityVo> initSelectAllByCons(int buildingId, int storeyId, int roomId, int now, int size) {
        PageHelper.startPage(now,size);
        List<ElectricityVo> arr = electricityMapper.initSelectAllByCons(buildingId,storeyId,roomId);
        return new PageInfo<>(arr);
    }

    public void modifyStatus(Integer id, Integer status) {
        electricityMapper.modifyStatus(id,status);
    }

    public void deleteEle(Integer id) {
        electricityMapper.deleteByPrimaryKey(id);
    }

    public void addEle(Electricity electricity) {
        electricity.setElectricitystatus(0);
        electricityMapper.insert(electricity);
    }

    public ElectricityVo selectById(Integer id) {
        return  electricityMapper.selectById(id);
    }

    public void modifyEle(Electricity electricity) {
        electricity.setElectricitystatus(0);
        electricityMapper.updateByPrimaryKey(electricity);
    }
}
